#include <QApplication>
#include <QFileInfo>
#include <QDebug>
#include "MenuFactory.h"
#include "Node.h"

#define ADD(text, slot) \
    act = new QAction(text, parent); \
    call[0] = slot; \
    act->setData(call); \
    act->connect(act, SIGNAL(triggered()), reciever, SLOT(call())); \
    menu->addAction(act);

QMenu* MenuFactory::create(Node* node, QWidget* parent, QObject *reciever)
{
    QMenu *menu = new QMenu(parent);

    QVariantList call;
    call << "" << QVariant::fromValue(node);
    QAction *act = NULL;

    switch(node->nodeType()){
    case FileType:{
        ADD(QApplication::tr("Open", "Menu"), "open");
        if (node->extension() == "ui" || node->extension() == "qrc"){
            ADD(QApplication::tr("Compile", "Menu"), "compile");
        }
        break;
    }
    case PyModuleType: {
        ADD(QApplication::tr("Add new...", "Menu"), "moduleAdd");
        break;
    }
    case DirectoryType: {
        ADD(QApplication::tr("Add new...", "Menu"), "directoryAdd");
        break;
    }
    case DesignerType:{
        ADD(QApplication::tr("Add form...", "Menu"), "formAdd");
        ADD(QApplication::tr("Compile all", "Menu"), "compileAll");
        break;
    }
    case ResourcesType:{
        ADD(QApplication::tr("Compile all", "Menu"), "compileAll");
        break;
    }
    default:
        break;

    }

    menu->addSeparator();
    ADD(QApplication::tr("Rename", "Menu"), "rename")
    ADD(QApplication::tr("Delete", "Menu"), "delete")

    return menu;
}

